/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.onurkagan.ksnack_lib.Animations;

import ohos.agp.animation.AnimatorProperty;
import ohos.agp.components.Component;

/**
 * 平移动画
 *
 * @author dev
 * @since 2021-07-08
 */
public class Slide {
    /**
     * 默认动画时间
     */
    private static long DEFAULT_ANIM_TIME = 400;
    /**
     * 动画
     */
    private static AnimatorProperty animation;

    /**
     * Up
     *
     * @since 2021-07-08
     */
    public static class Up {
        // Slide up anim without optional anim time and interpolator.

        /**
         * getAnimation
         *
         * @param component component
         * @param rlvHost rlvHost
         * @return animation
         */
        public static AnimatorProperty getAnimation(Component component, Component rlvHost) {
            final int len = 155;
            if (isMinimalKSnack(rlvHost)) {
                animation = rlvHost.createAnimatorProperty()
                    .moveFromY(-component.getHeight() - len).moveToY(component.getHeight());
            } else {
                animation = rlvHost.createAnimatorProperty()
                    .moveFromY(component.getHeight()).moveToY(component.getHeight() - len);
            }
            animation.setDuration(DEFAULT_ANIM_TIME);
            return animation;
        }

        // Slide up anim with optional anim time.

        /**
         * getAnimation
         *
         * @param component component
         * @param rlvHost rlvHost
         * @param millisecond millisecond
         * @return animation
         */
        public static AnimatorProperty getAnimation(Component component, Component rlvHost, int millisecond) {
            final int len = 155;
            if (isMinimalKSnack(rlvHost)) {
                animation = rlvHost.createAnimatorProperty()
                    .moveFromY(-component.getHeight() - len).moveToY(component.getHeight());
            } else {
                animation = rlvHost.createAnimatorProperty()
                    .moveFromY(component.getHeight()).moveToY(component.getHeight() - len);
            }
            animation.setDuration(millisecond);
            return animation;
        }
    }

    /**
     * Down
     *
     * @since 2021-07-08
     */
    public static class Down {
        // Slide down anim without optional anim time and interpolator.

        /**
         * getAnimation
         *
         * @param component component
         * @param rlvHost rlvHost
         * @return animation
         */
        public static AnimatorProperty getAnimation(Component component, Component rlvHost) {
            final int len = 155;
            if (isMinimalKSnack(rlvHost)) {
                animation = rlvHost.createAnimatorProperty()
                    .moveFromY(component.getHeight()).moveToY(component.getHeight() - len);
            } else {
                animation = rlvHost.createAnimatorProperty()
                    .moveFromY(component.getHeight() - len).moveToY(component.getHeight());
            }
            animation.setDuration(DEFAULT_ANIM_TIME);
            return animation;
        }

        // Slide down anim with optional anim time.

        /**
         * getAnimation
         *
         * @param component component
         * @param rlvHost rlvHost
         * @param millisecond millisecond
         * @return animation
         */
        public static AnimatorProperty getAnimation(Component component, Component rlvHost, int millisecond) {
            final int len = 155;
            if (isMinimalKSnack(rlvHost)) {
                animation = rlvHost.createAnimatorProperty()
                    .moveFromY(component.getHeight()).moveToY(component.getHeight() - len);
            } else {
                animation = rlvHost.createAnimatorProperty()
                    .moveFromY(component.getHeight() - len).moveToY(component.getHeight());
            }
            animation.setDuration(millisecond);
            return animation;
        }
    }

    /**
     * 是最小的ksnack
     * isMinimalKSnack
     *
     * @param rlvHost rlv主机投放
     * @return false
     */
    public static boolean isMinimalKSnack(Component rlvHost) {
        if (rlvHost.getName().equals("minimal_snack_bar_rlv")) {
            return true;
        }
        return false;
    }
}
